<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //创建一个对象
        let teacher = {
            name: "邓睿",
            age: 18,
            web: "dengruicode.com"
        }
        console.log(teacher)

        //对象.属性=：（未存在的）增加
        teacher.height = 180
        console.log(teacher)

        //对象.属性=（已存在的）：更改
        teacher.web = "163.com"
        console.log(teacher)
        //delete:对象.属性 删除
        delete teacher.web
        console.log(teacher)

        //has接收属性in对象:对象里面是否存在此元素
        let has1 = "name" in teacher
        let has2 = "web" in teacher
        console.log(has1)
        console.log(has2)

        //Object.keys获取对象属性名数组的长度来知道对象的size
        console.log(Object.keys(teacher))
        console.log(Object.keys(teacher).length)

        //for...of可迭代对象X
        // for (let key of teacher) {
        //     console.log("key", key, "value", teacher[key])
        // }
        //for...in可枚举属性=>通过数组访问属性值
        for (let key in teacher) {
            console.log("key", key, "value", teacher[key])
        }
        // Object.entries获取对象键值对的数组
        console.log(Object.entries(teacher))
        //foreach遍历：
        Object.entries(teacher).forEach(([key, value]) => {
            console.log("foreachkey:", key, "foreachvalue:", value)
        })
    </script>
</body>

</html>